<#include "/common/_layout.html">
<#assign pageJavascript>
<script type="text/javascript" src="/assets/uploadfive/jquery.uploadifive.min.js"></script>
<link rel="stylesheet" type="text/css" href="/assets/uploadfive/uploadifive.css" />
<script type="text/javascript">
$(function(){
	var res = false;
	function tt(){
		var p =/^[0-9]+(.[0-9]{2})/; 
	    var intboot = $("#nameboot").val();
	    if(intboot.length<=0){
	    	$(".bot .Validform_checktip").removeClass("Validform_right");
	    	$(".bot .Validform_checktip").addClass("Validform_wrong");
	    	$(".bot .Validform_checktip").text("固件版本不能为空!");
	    }else{
		    if(p.test(intboot)){
		    	$(".bot .Validform_checktip").removeClass("Validform_wrong");
		    	$(".bot .Validform_checktip").addClass("Validform_right");
		    	$(".bot .Validform_checktip").text("通过信息验证！");
		    	res = true;
		    }else{
		    	$(".bot .Validform_checktip").removeClass("Validform_right");
		    	$(".bot .Validform_checktip").addClass("Validform_wrong");
		    	$(".bot .Validform_checktip").text("固件版本号格式不正确!");
		    }
	    }
	}
	$("#nameboot").blur(function(){
		tt();

	  });
	$('#filebtn').uploadifive({
		buttonClass:'btn btn-info',buttonText : '导入',fileSizeLimit : '3000',
	    uploadScript : '/admin/uploadfile',formData:{pid:$('#pid').val()},
	    multi:false,
	    onUploadComplete : function(file, data) {
	    	layer.msg("导入成功！");
	    	$("#fileurla").val(data);
	    }
	});
	$('#filebtns').uploadifive({
		buttonClass:'btn btn-info',buttonText : '导入',fileSizeLimit : '3000',
	    uploadScript : '/admin/uploadfile',formData:{pid:$('#pid').val()},
	    multi:false,
	    onUploadComplete : function(file, data) {
	    	layer.msg("导入成功！");
	    	$("#fileurlb").val(data);
	    }
	});
	$("#sub").click(function(){
		tt();
		if(res){
			$("#sub").attr('type','submit');
			$("#form1").Validform({
			 tiptype:5,
			beforeSubmit:function(curform){
				var para = $(curform).serializeObject();
				$.extend(para,{"deviceboot.id":"${(deviceboot.id)!}"});
				var loadIndex = layer.load();
				$.post("/admin/boot/save?v="+Math.random(),para,function(data){
		           if (data.msg == 'success') {
		        	   layer.alert('保存成功！',{icon: 6},function(index){
		        		   layer.close(index);
		        		   window.location="/admin/boot";
		        	   });
		           }
			       else {layer.msg('保存失败！', {icon: 5});}
		           layer.close(loadIndex);
				});
				return false;	
			}
			});
		}else{
			$("#sub").attr('type','button');
			$("#nameboot").focus();
		}		
	})
});
</script>
</#assign>
<@layout pageTitle="固件管理" pageJavascript=pageJavascript pageCss=pageCss>	
<h3 class="page-header">固件管理</h3>
<form id = "form1" class="form-horizontal">
  <div class="form-group bot">
    <label for="name" class="col-sm-2 control-label">固件版本</label>
    <div class="col-xs-10 col-sm-3">
      <input type="text" id="nameboot" value="${(deviceboot.name)!}" name="name"  placeholder="输入正确的格式：11.01" class="form-control">
    </div>
    <span class="Validform_checktip"></span>
  </div>   
  <div class="form-group">
    <label for="product" class="col-sm-2 control-label">对应产品</label>
    <div class="col-xs-10 col-sm-3">
	    	<select name="device.pid" id="pid" class="form-control">
			<#if plist??>
			<#if plists??>
			<#list plists as data>
	    	<option value="${data.id}">${data.pname}</option>
	    	</#list>
    		</#if>
			<#list plist as data>
			<option value="${data.id}">${data.pname}</option>
			</#list>
			</#if>		
			</select>
    </div>
  </div>
  <div class="form-group">
    <label for="version" class="col-sm-2 control-label">备注</label>
    <div class="col-xs-10 col-sm-3">
      <textarea id="version" rows="8" cols="50" name="version" datatype="*0-200"  class="form-control">${(deviceboot.version)!}</textarea>
    </div>
  </div>
    <div class="form-group">
    <label for="fileurla" class="col-sm-2 control-label">导入附件A</label>
    <div class="col-xs-7 col-sm-2">
    <input type="text"  id="fileurla" value="${(deviceboot.fileurla)!}" name="fileurla" class="form-control">   
    </div>
    <div class="col-xs-3 col-sm-1">
    <input type="file" id="filebtn">      
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="button" class="btn btn-success" id="sub">提交</button>
      <a href="/admin/system/boot" class="btn btn-default">取消</a>
    </div>
  </div>
</form>
</@layout>